package com.gla.dao;

import com.gla.domain.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FYH_ShopMapper {
    @Select("SELECT * FROM SHOP WHERE id = #{shop_id}")
    Shop selectOneShop(Integer shop_id);

    @Select("SELECT * FROM SHOP")
    List<Shop> selectAllAhop();

    @Select("SELECT * FROM COMMODITY WHERE shop_id = #{shop_id} AND p_o_u = #{pou}")
    List<Commodity> selectCommodityByShopIdAndPOU(Integer shop_id, Integer pou);

    @Select("SELECT * FROM COMMODITY WHERE id = #{cm_id}")
    Commodity selectCommodityById(Integer cm_id);

    @Select("SELECT * FROM COMMODITY WHERE p_o_u = #{pou}")
    List<Commodity> selectAllCommodityByPOU(Integer pou);

    @Select("SELECT * FROM EVALUATION WHERE commodity_id = #{cmid}")
    List<FYH_Evaluation> selectEvaluationByCMId(Integer cmid);

    @Select("SELECT * FROM EVALUATION WHERE shop_id = #{spid}")
    List<FYH_Evaluation> selectEvaluationBySPId(Integer spid);

    @Select("SELECT * FROM USER WHERE id = #{uid}")
    User selsetUserById(Integer uid);

    @Select("SELECT * FROM VIDEO WHERE commodity_id = #{cmid}")
    List<FYH_Vedio> selectVedioByCMId(Integer cmid);

    @Select("SELECT * FROM VIDEO WHERE type_id = #{type} AND id <> #{id}")
    List<FYH_Vedio> selectVedioByType(Integer type, Integer id);

    @Select("SELECT * FROM VIDEO WHERE id = #{id}")
    FYH_Vedio selectVedioById(Integer id);

    @Select("SELECT * FROM SHOPPINGCART WHERE commodity_id = #{cmid} AND user_id = #{uid} AND number > 0")
    FYH_ShopCar selectOneCarByCMIdAndUId(Integer cmid, Integer uid);

    @Select("SELECT * FROM SHOPPINGCART WHERE commodity_id = #{cmid} AND user_id = #{uid} AND number = 0")
    FYH_ShopCar selectOneCarByCMIdAndUIdNIS0(Integer cmid, Integer uid);

    @Select("SELECT * FROM SHOPPINGCART WHERE id = #{id}")
    FYH_ShopCar selectOneCarById(Integer id);

    @Insert("INSERT INTO SHOPPINGCART (number, commodity_id, user_id) VALUES (1, #{cmid}, #{uid})")
    void insertOneCar(Integer cmid, Integer uid);

    @Delete("DELETE FROM SHOPPINGCART WHERE id = #{id}")
    void deleteOneCar(Integer id);

    @Update("UPDATE SHOPPINGCART SET number = #{num} WHERE id = #{id}")
    void updateOneCar(Integer id, Integer num);

    @Select("SELECT * FROM SHOP WHERE latitude > #{mila} AND latitude < #{mxla} AND  longitude > #{milo} AND  longitude < #{mxlo}")
    List<Shop> selectShopNear(Double mila, Double mxla, Double milo, Double mxlo);
}
